﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using WebApplication.Models;
using Newtonsoft.Json;

namespace WebApplication
{
    /// <summary>
    /// Handler 的摘要说明
    /// </summary>
    public class HttpHandler : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            if (context.Request.HttpMethod == "POST" && context.Request.QueryString["Action"] == "GetJson")
            {
                context.Response.ContentType = "text/javascript";
                context.Response.Write(this.GetJson());
            }
            else
            {
                context.Response.ContentType = "text/plain";
                context.Response.Write("Hello World");
            }
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
        private String GetJson()
        {
            User user = new User()
            {
                Name = "Jiangzm",
                Age = 20,
                Sex = true,
                Number = "1007",
                Birthday = DateTime.Now
            };
            return JsonConvert.SerializeObject(user);
        }
    }
}